package com.jia.product.controller;


import com.jia.mybatis.page.PageResult;
import com.jia.product.entity.Attr;
import com.jia.product.service.AttrService;
import com.jia.product.vo.AttrRespVo;
import com.jia.product.vo.AttrVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 商品属性(Attr)表控制层
 *
 * @author makejava
 * @since 2025-07-08 18:15:24
 */
@RestController
@RequestMapping("attr")
public class AttrController {
    /**
     * 服务对象
     */
    @Resource
    private AttrService attrService;

    @PostMapping("/insert")
    public Attr insert(@RequestBody AttrVo attr) {
        attrService.saveVo(attr);
        return attr;
    }

    @GetMapping("/page/{attrType}/{catelogId}")
    public PageResult<AttrRespVo> page(@RequestParam(defaultValue = "0", required = false) long current,
                                       @RequestParam(defaultValue = "10", required = false) long size,
                                       @RequestParam(required = false) String key,
                                       @PathVariable String attrType,
                                       @PathVariable Long catelogId
    ) {
        return attrService.pageQuery(current, size, key, attrType, catelogId);
    }

    @GetMapping("/info/{attrId}")
    public AttrRespVo info(@PathVariable Long attrId) {
        return attrService.selectInfo(attrId);
    }


    @PutMapping("/update")
    public AttrVo update(@RequestBody AttrVo attrVo) {
        return attrService.updateInfo(attrVo);
    }


}

